﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ChineseSchool.BLL;
using ChineseSchool.Models.Hethong;

namespace ChineseSchool
{
    public partial class News : System.Web.UI.Page
    {
        public string strPaging = "";
        private int page = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "Học tiếng trung hiệu quả";
            if (!IsPostBack)
            {
                lblNewsContent.Text = LoadNewsContent();
                //page = (Request.QueryString["page"] + "" != "") ? int.Parse("0" + Request.QueryString["page"]) : 1;
                //DataSet ds = (new B_News()).GetPhanTrangDataSet("News_PagingByNewsTypeID", page, 2, 5, 1);
                //if (ds.Tables.Count > 0)
                //{
                //    if (ds.Tables[0].Rows.Count > 0)
                //    {
                //        //lvListNew.DataSource = ds.Tables[0];
                //        //lvListNew.DataBind();
                //    }
                //    if (ds.Tables[1].Rows.Count > 0)
                //    {
                //        strPaging = ds.Tables[1].Rows[0][0] + "";
                //    }
                //    lblPaging.Text = strPaging;
                //}
            }
        }

        public string LoadNewsContent()
        {
            string format = "ddd, dd/MM/yyyy h:mm:ss tt";
            string strNews = "";            
            List<M_NewsType> lstNewsType = new B_NewsType().GetAlls();
            if (lstNewsType != null && lstNewsType.Count > 0)
            {
                for (int i = 0; i < lstNewsType.Count; i++)
                {
                    strNews += "<h1><a href=\"" + Util.MakeLinkNewsTypeDetail(lstNewsType[i].newsTypeID.ToString(), Encode.Uni2KD(lstNewsType[i].newsTypeName.ToString())) + "\" title=\"" + lstNewsType[i].newsTypeName.ToString() + "\">" + lstNewsType[i].newsTypeName.ToString() + "</a></h1>";
                    int NewsTypeID = lstNewsType[i].newsTypeID;
                    List<M_News> lstNews = (new B_News()).GetBy_NewsTypeID(NewsTypeID);
                    if (lstNews != null && lstNews.Count > 0)
                    {
                        for (int j = 0; j < lstNews.Count; j++)
                        {
                            strNews += "<article class=\"alt\">";
                            strNews += "<div class=\"newstitle\">";
                            strNews += "<div class=\"newstitle_img\">";
                            strNews += "<div class=\"featured-thumbnail\">";
                            strNews += "<a href=\"" + Util.MakeLinkNewsDetail(lstNews[j].newsID.ToString(), Encode.Uni2KD(lstNews[j].title.ToString())) + "\">";
                            strNews += "<img width=\"100\" height =\"60\" title=\"" + lstNews[j].title.ToString() + "\" alt=\"" + lstNews[j].title.ToString() + "\" class=\"attachment-medium-post-thumbnail wp-post-image\"";
                            strNews += " src=\"" + lstNews[j].imageUrl.ToString() + "\"/>";
                            strNews += "</a></div></div>";
                            strNews += "<div class=\"newstitle_imf\">";
                            strNews += "<h2 class=\"title\">";
                            strNews += "<a rel=\"Tin tức nổi bật\" title=\"" + lstNews[j].title.ToString() + "\" href=\"" + Util.MakeLinkNewsDetail(lstNews[j].newsID.ToString(), Encode.Uni2KD(lstNews[j].title.ToString())) + "\">";
                            strNews += "" + lstNews[j].title.ToString() + "</a></h2>";
                            strNews += "<div class=\"post-meta\">";
                            strNews += "<span class=\"post-date\">" + lstNews[j].postDate.ToString(format) + "</span> &nbsp; ";
                            strNews += " Posted by <a rel=\"author\" title=\"Posts by admin\" href=\"#\">admin</a>";
                            strNews += "</div></div>";
                            strNews += "</div>";
                            strNews += "<div class=\"clear\"></div>";
                            strNews += "<div class=\"post-excerpt\">";
                            strNews += "<div> " + lstNews[j].summary.ToString() + "&nbsp;";
                            strNews += " <a class=\"read-more\" ";
                            strNews += " href=\"" + Util.MakeLinkNewsDetail(lstNews[j].newsID.ToString(), Encode.Uni2KD(lstNews[j].title.ToString())) + "\">Xem Chi Tiết</a></div>";
                            strNews += "</div></article>";                            
                        }
                    }
                }
            }
            return strNews;
        }
    }
}